Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (vicknick, AndrewAMD), 1,292 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
turn based game #317119
03/29/10 12:03
03/29/10 12:03
Joined: Jan 2010
Posts: 10
North Queensland, Australia
B
bilby11 Offline OP
Newbie
bilby11  Offline OP
Newbie
B

Joined: Jan 2010
Posts: 10
North Queensland, Australia
gid day all,

I am trying to make a Tic Tac Toe (or checkers) game for my little brother which is turn based game so that I can play with him. Can anyone point in the right direction of a turn based script for Tic Tac Toe &/or checkers, or simular. I have been about to get my board developed, and is using mouse_ent with ent_morph to change board pieces into either X or O, but I have not been able to work out how to change from one player to the other player. Also, if someone can explain how to c-scan or c-trace or whatever to work out if someone has won, that would be very helpful (ie three X in a row).

Thank you in advance
Bilby11

Re: turn based game [Re: bilby11] #317121
03/29/10 12:32
03/29/10 12:32
Joined: Feb 2004
Posts: 334
metal Offline
Senior Member
metal  Offline
Senior Member

Joined: Feb 2004
Posts: 334
you could use something like
BOOL turn=false; //false => Player1 has to set his marker; true for Player2
if you click at the board you can chekc the value of "turn":
if(turn==false){change board piece to X;turn =true;}
else{change it to O; turn=false;}

Re: turn based game [Re: metal] #317138
03/29/10 14:23
03/29/10 14:23
Joined: Dec 2008
Posts: 1,660
North America
Redeemer Offline
Serious User
Redeemer  Offline
Serious User

Joined: Dec 2008
Posts: 1,660
North America
Quote:
if(turn==false){change board piece to X;turn =true;}
else{change it to O; turn=false;}

Better way:
Code:
turn = (turn==false);



The best way to determine who has won is to use a 2 dimensional array that carries an index for every space on the board. You can fill up this array as the game is played out. At the end of every turn just perform some checks to see if that player has "connected" three of his own tiles in a row, perhaps like this:

Code:
var game_board[3][3]; // this is your game board
var winner = 0; // the winner of this game. 0=nobody, 1=player1, 2=player2, etc.

function check_across( row, player )
{
   // check if the player wins
   if( game_board[row][0] == player )
   if( game_board[row][1] == player )
   if( game_board[row][2] == player )
   {
     // the player who placed all these identical pieces in a row wins!
     winner = player;
   }
}

function check_down( column, player )
{
   // check if the player wins
   if( game_board[0][column] == player )
   if( game_board[1][column] == player )
   if( game_board[2][column] == player )
   {
     // the player who placed all these identical pieces in a column wins!
     winner = player;
   }
}

function check_diagonals( player )
{
   // check if the player wins down and right
   if( game_board[0][0] == player )
   if( game_board[1][1] == player )
   if( game_board[2][2] == player )
   {
     // the player who placed all these identical pieces down and right wins!
     winner = player;
   }

   // check if the player wins down and left
   if( game_board[0][2] == player )
   if( game_board[1][1] == player )
   if( game_board[2][0] == player )
   {
     // the player who placed all these identical pieces down and left wins!
     winner = player;
   }
}

function end_of_turn( player )
{
   var c;

   // this function checks to see if a player won the game
   for( c=0; c<3; c++ )
   {
      check_across( c, player );
      check_down( c, player );
   }
   check_diagonals( player );

   // did this player win?
   if( winner == player )
   {
      // celebrate his winning, restart the game, etc. etc.
   }
}



Just call the end_of_turn() function at the end of every player's turn. Remember to pass the player number to the function when you call it. wink


Eats commas for breakfast.

Play Barony: Cursed Edition!
Re: turn based game [Re: Redeemer] #317232
03/30/10 09:34
03/30/10 09:34
Joined: Jan 2010
Posts: 10
North Queensland, Australia
B
bilby11 Offline OP
Newbie
bilby11  Offline OP
Newbie
B

Joined: Jan 2010
Posts: 10
North Queensland, Australia
Gid day;

Thank you Metal, I have been able to get the turn about working.

Thank you Redeemer for your scoring snipet, however I have been getting a Syntex error: Can't convert EQ:FIXED:POINTER:LONG.
<if (game_board[row][0] == player;

Can you help me out? What have I been doing wrong?

Thank you in advance
Bilby11


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1