/// <summary> /// Check all collisions and collide where necessary /// </summary> /// <param name="platforms">List of all platforms to check</param> /// <param name="player">The player to collide with</param> /// <param name="aspectRatio">Describes the ratio of the game window height to width, used because sizes are defined as a fraction of the window size</param> public void collisions(List<Platform> platforms, Player player, int width, int height) { //Assume no collision bool hasCollide = false; //Assume the player has left the ground //If the player remains on the ground, that condition will be handled in the collision if (player.state[Constants.AIR_STATE] == Constants.ON_GROUND) player.state[Constants.AIR_STATE] = Constants.CHARGE_READY; //Check each platform and collide where necessary foreach (Platform plat in platforms) { if (plat.collides(player, width, height)) { collide(plat, player, width, height); //Collide with rectangle //Console.WriteLine(platforms.IndexOf(plat).ToString()); hasCollide = true; } } //If there was no collision, set state accordingly if (!hasCollide) player.state[Constants.COLLISION_STATE] = Constants.COLLIDE_NONE; }
static void Main(string[] args) { var board = new Board(50); //look at the collectable's start position var player = new Player(board._Size); //i have a strong feeling that i went too deep and overcomplicated this severly, //or at least in my mind i did and i psyched myself out. //or i justwas not finding the right thing about lists... it's possible //but i was looking all day trying to figure it out. var rnd = new Random(); List<Collectable> collectablesList = new List<Collectable>() { new Collectable(board._Size, rnd), new Collectable(20, 20, board._Size, rnd), new Collectable(1, 1, board._Size, rnd), new Collectable(3, 3, board._Size, rnd), new Collectable(6, 42, board._Size, rnd), new Collectable(8, 8, board._Size, rnd), new Collectable(10, 17, board._Size, rnd), new Collectable(25, 37, board._Size, rnd), new Collectable(9, 28, board._Size, rnd), new Collectable(3, 19, board._Size, rnd) }; var input = ""; while (input != "q") { if (input == "h") { player.MoveLeft(); } if (input == "j") { player.MoveDown(); } if (input == "k") { player.MoveUp(); } if (input == "l") { player.MoveRight(); } //Im still looking at how to properly access the list by an calling it... //this is where i was thinking that i really overcomplicated it because //it should not be this difficult to call a list with variables in it //and it shouldn't be this difficult to find something online about it. //i don't know how to call this properly - I want to call the name of the list //and have vars in the list follow, but I had such a hard time trying to find //accessors. //my thot process was to associate each variable in the collectablesList list with the same //properties... apparently it didn't work. foreach (Collectable c in collectablesList) { c.Move(); c.UpdateWithPlayer(player); } board.Draw(player, collectablesList); input = Console.ReadLine(); Console.SetCursorPosition(0, Console.CursorTop - 1); } // while loop for game "tick" } // main function
/// <summary> /// Collide a platform with a player /// </summary> /// <param name="plat">Platform to collide</param> /// <param name="player">Player to collide</param> /// <param name="aspectRatio">Describes the ratio of the game window height to width, used because sizes are defined as a fraction of the window size</param> private void collide(Platform plat, Player player, int width, int height) { ////Point describing the top left of the player //Vector2d amax = new Vector2d( ( player.position.X - player.charSize.X ) / width, ( player.position.Y + player.charSize.Y ) / height); ////Point describing the bottom right of the player //Vector2d amin = new Vector2d( ( player.position.X + player.charSize.X ) / width, ( player.position.Y - player.charSize.Y ) / height); ////Point describing the top left of the platform //Vector2d bmax = new Vector2d( ( plat.position.X - plat.platSize.X ) / width, ( plat.position.Y + plat.platSize.Y ) / height); ////Point describing the bottom right of the player //Vector2d bmin = new Vector2d( ( plat.position.X + plat.platSize.X ) / width, ( plat.position.Y - plat.platSize.Y ) / height); //Point describing the top left of the player Vector2d amax = new Vector2d((player.position.X + player.charSize.X), (player.position.Y - player.charSize.Y)); //Point describing the bottom right of the player Vector2d amin = new Vector2d((player.position.X - player.charSize.X), (player.position.Y + player.charSize.Y)); //Point describing the top left of the platform Vector2d bmax = new Vector2d((plat.position.X + plat.platSize.X), (plat.position.Y - plat.platSize.Y)); //Point describing the bottom right of the player Vector2d bmin = new Vector2d((plat.position.X - plat.platSize.X), (plat.position.Y + plat.platSize.Y)); //Declare vector for displacement Vector2d mtd = new Vector2d(0, 0); //displacements in each direction double right = bmin.X - amax.X; double left = bmax.X - amin.X; double bottom = bmin.Y - amax.Y; double top = bmax.Y - amin.Y; //The minimum displacement is the collision direction double min = Math.Min(Math.Min(Math.Abs(left), Math.Abs(right)), Math.Min(Math.Abs(top), Math.Abs(bottom))); //check collisions in each direction if (Math.Abs(left) == min) { mtd.X = left; collideLeft(player); } if (Math.Abs(right) == min) { mtd.X = right; collideRight(player); } if (Math.Abs(top) == min) { mtd.Y = top; collideTop(player); } if (Math.Abs(bottom) == min) { mtd.Y = bottom; collideBottom(player); } player.position += mtd; }
static void Main(string[] args) { Player playerOne = new Player("Marko", 300, 20); Player playerTwo = new Player("JABE", 200, 30); string option = "Continue"; Console.WriteLine("<Attack> <Defend> <Quit>"); option = Console.ReadLine(); option = option.ToLower().Trim(); Console.Clear(); while (option != "quit") { switch (option) { case "attack": if (playerTwo.HitPoints != 0) { Console.WriteLine(playerOne.Name + " attacks!"); playerTwo.TakeDamage(); playerTwo.Print(); option = Console.ReadLine(); option = option.ToLower().Trim(); Console.Clear(); } else { Console.WriteLine(playerTwo.Name + " dies."); return; } break; case "defend": Console.WriteLine(playerTwo.Name + " attacks!"); playerOne.TakeDamage(); playerOne.Print(); option = Console.ReadLine(); option = option.ToLower().Trim(); Console.Clear(); break; case "quit": break; default: Console.WriteLine("Invalid option, try again.\n"); option = Console.ReadLine(); option = option.ToLower().Trim(); break; } } Console.Clear(); Console.WriteLine("Quit."); }
static void Main(string[] args) { GameMap map = new GameMap(); Player player = new Player(ref map); while (true) { map.Print(); Console.Write("Good sir, would you kindly enter a cardinal direction? "); player.ParseDirection(ref map, Console.ReadLine()); } }
static void Main(string[] args) { Player player = new Player(); player.Name = "player1"; //OK //player.Life = 10; //错误,Life是只读属性 Console.WriteLine(player.Name); // 输出Name Console.WriteLine(player.Life); // 输出Life的值100 // 输入任意键退出 Console.ReadKey(); }
static void Main(string[] args) { Player player1 = new Player(); //创建一个Player对象 Console.WriteLine(Player.count);// 输出1,有1个Player Player player2 = new Player();// 又创建一个Player对象 Console.WriteLine(Player.count); // 输出2,有2个Player // n = player2.count; 错误用法,静态成员不能被对象直接调用 // 输入任意键退出 Console.ReadKey(); }
public void UpdateWithPlayer(Player player) { var calculateDistance = new DistanceCalculator(); var distance = calculateDistance.distance(this._Item, player._Item); if (distance < 4) { _PlayerGotTooClose = true; } if (distance == 0) { _PlayerCollidedWithCollectable = true; player.currentNumberOfCollectedItems += 1; } }
List<Vector2d> Vertices; //Used in rendering /// <summary> /// This method overrides the base OnLoad method from GameWindow /// /// It runs when the game is first loaded /// </summary> /// <param name="e"></param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); //Set the title of the game Title = "Game!"; //Make a character object and assign it to the player variable player = new Char1(); //Load the level platforms = loadPlatforms(); //Set the background color of the window GL.ClearColor(currentColor); }
public void Draw(Player player, List<Collectable> collectables) { Console.Out.WriteLine(" "); var boundingBar = " "; for (var x = 0; x < _Size; x++) { boundingBar += "-"; } Console.Out.WriteLine(boundingBar); for (var r = 0; r < _Size; r++) { var rowString = ""; for (var c = 0; c < _Size; c++) { var shouldDrawCollectable = false; foreach (Collectable collectableItem in collectables) { if (collectableItem.IsCollectablePosition(c, r)) { shouldDrawCollectable = true; } } //var shouldDrawCollectable = collectables.Any(co => co.IsCollectablePosition(c, r)); //these lines of code, 44 and 38-42, are telling the program to do the same thing - they're just set up differently. //the => is a lambda... read about this more. if (player.IsPlayerPosition(c, r)) { rowString += "@"; } else if (shouldDrawCollectable) { rowString += "C"; } else { rowString += this._Board[r, c]; } } Console.Out.WriteLine(String.Format("|{0}|", rowString)); } Console.Out.WriteLine(boundingBar); Console.Out.WriteLine("Type 'q' and enter to quit;" + "player count:" + player.currentNumberOfCollectedItems); Console.SetCursorPosition(0, Console.CursorTop - (_Size + 4)); }
/// <summary> /// Used to check collision with the player, returns true of this platform and the palyer collide /// </summary> /// <param name="player">the Player</param> /// <returns>returns true of this platform and the palyer collide</returns> public bool collides(Player player, int width, int height) { //platform corners, Min is bottom left and max is top right Vector2d platMin = position - platSize; Vector2d platMax = position + platSize; //player corners, Min is bottom left and max it top right Vector2d playerMin = player.position + player.velocity - player.charSize; Vector2d playerMax = player.position + player.velocity + player.charSize; //if statement checks the sides of the platform compared to the sides of the player if (platMin.X > playerMax.X || //if the left of the platform is further right than the right side of the player or platMin.Y > playerMax.Y || //the bottom of the platform is higher than the top of the player or platMax.X < playerMin.X || //the right of the platform is further left than the left of the player platMax.Y < playerMin.Y) //the top of the platform is lower than the bottom of the player { return false; //then there is no collision, so return false } return true; //otherwise, there is a collision, so return true }
/// <summary> /// collide with a platform to the bottom /// </summary> /// <param name="player"></param> private void collideBottom(Player player) { if (player.velocity.Y < 0) player.velocity.Y = 0; player.state[Constants.COLLISION_STATE] = Constants.COLLIDE_BOTTOM; player.state[Constants.AIR_STATE] = Constants.ON_GROUND; player.state[Constants.GRAB_STATE] = Constants.GRAB_NONE; }
/// <summary> /// collide with a platform to the top /// </summary> /// <param name="player"></param> private void collideTop(Player player) { if (player.velocity.Y > 0) player.velocity.Y = 0; player.state[Constants.COLLISION_STATE] = Constants.COLLIDE_TOP; }
/// <summary> /// collide with a platform to the right /// </summary> /// <param name="player"></param> private void collideRight(Player player) { if (player.velocity.X > 0) player.velocity.X = 0; player.state[Constants.COLLISION_STATE] = Constants.COLLIDE_RIGHT; }
/// <summary> /// collide with a platform to the left /// </summary> /// <param name="player"></param> private void collideLeft(Player player) { if (player.velocity.X < 0) player.velocity.X = 0; player.state[Constants.COLLISION_STATE] = Constants.COLLIDE_LEFT; }
public void Start() { Console.WriteLine("Welcome to The HIGH-LOW Games"); Console.WriteLine("Let's Have some FUN!"); Console.WriteLine("First Player Name :"); string name1 = Console.ReadLine(); Console.WriteLine("Second Player Name :"); string name2 = Console.ReadLine(); Console.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"); Player p1 = new Player(name1); Player p2 = new Player(name2); Deck deck = new Deck(); //create deck for play game while (deck.Cards.ToArray().Length > 0) { p1.DrawToHand(deck); p2.DrawToHand(deck); p1.ShowCard(); p2.ShowCard(); //Console.WriteLine(p1.NamePlayer + " got " + p1.LastLastCardInHand()().Face + " " + p1.LastLastCardInHand()().Suit + "" + p1.LastLastCardInHand()().Rank); //Console.WriteLine(p2.NamePlayer + " got " + p2.LastCardInHand().Face + " " + p2.LastCardInHand().Suit + "" + p2.LastCardInHand().Rank); if (p1.LastCardInHand().Rank < p2.LastCardInHand().Rank) { p1.Score = p1.Score + 2; Console.WriteLine(p1.NamePlayer + " Score is " + p1.Score); } else if (p1.LastCardInHand().Rank > p2.LastCardInHand().Rank) { p2.Score = p2.Score + 2; Console.WriteLine(p2.NamePlayer + " Score is " + p2.Score); } else //when rank card is equal { int oldRank = p1.LastCardInHand().Rank; //keep old rank for draw cards to looping for for (int i = 0; (i < oldRank) && (deck.Cards.ToArray().Length > 0); i++) //draw card as number of rank from deck { p1.DrawToHand(deck); p2.DrawToHand(deck); } p1.ShowCard(); // show last card p2.ShowCard(); Console.WriteLine(2 + (oldRank * 2)); if (p1.LastCardInHand().Rank < p2.LastCardInHand().Rank) { p1.Score = p1.Score + 2 + (oldRank * 2); Console.WriteLine(p1.NamePlayer + " Score is " + p1.Score); } else if (p1.LastCardInHand().Rank > p2.LastCardInHand().Rank) { p2.Score = p2.Score + 2 + (oldRank * 2); Console.WriteLine(p2.NamePlayer + " Score is " + p2.Score); } else { deck.PutBack(p1.CardInHand); // putback all cards in hand to deck deck.PutBack(p2.CardInHand); p1.ClearCardsInHand(); //clear all cards in hand p2.ClearCardsInHand(); } } Console.WriteLine("#########################################################"); } if (p1.Score > p2.Score) { Console.WriteLine(p1.NamePlayer + " is The winner with " + p1.Score + " score "); } else if (p1.Score < p2.Score) { Console.WriteLine(p2.NamePlayer + " is The winner with " + p2.Score + " score "); } else { Console.WriteLine(p1.NamePlayer + " and " + p2.NamePlayer + " Draw!!"); } }
static void Main(string[] args) { Console.Write("Name A : "); Player player1 = new Player(Console.ReadLine()); Console.Write("Name B : "); Player player2 = new Player(Console.ReadLine()); List<Cards> allCard = new List<Cards>(); for(int i=1; i<=13; i++) { for(int j=1; j<=4;j++) { allCard.Add(new Cards(i, j)); } } allCard = ShuffleList(allCard); for(int i=0;i<52;i+=2) { player1.addCard(allCard[i]); player2.addCard(allCard[i + 1]); } do { if(player1.getNumdeck()==26) { Console.Write("\nStart Game, Each player has " + player1.getNumdeck() + " Cards.\n"); } else if(player1.getNumdeck()==1) { Console.Write("\nNext Round, Each player has " + player1.getNumdeck() + " Card.\n"); } else Console.Write("\nNext Round, Each player has " + player1.getNumdeck() + " Cards.\n"); Cards c1 = player1.Draw(); Console.Write(player1.getName() + " Draw : " + c1.nameRank() + c1.nameSuit()+"\n"); Cards c2 = player2.Draw(); Console.Write(player2.getName() + " Draw : " + c2.nameRank() + c2.nameSuit()+"\n"); if (c1.getRank()<c2.getRank()) { Console.WriteLine(player1.getName() + " Win! and get 2 cards." ); player1.addPile(c1); player1.addPile(c2); } else if (c1.getRank() > c2.getRank()) { Console.WriteLine(player2.getName() + " Win! and get 2 cards." ); player2.addPile(c1); player2.addPile(c2); } else { int i,round; List<Cards> tempc1 = new List<Cards>(); List<Cards> tempc2 = new List<Cards>(); tempc1.Add(c1); tempc2.Add(c2); if (player1.getNumdeck() < c1.getRank()) { round = player1.getNumdeck(); } else round = c1.getRank(); Console.WriteLine("Card is equal at rank " + Convert.ToString(c1.getRank()) + "\nEach player draw " + Convert.ToString(round) + " Cards"); for (i=0;i<round;i++) { tempc1.Add(player1.Draw()); tempc2.Add(player2.Draw()); } Console.WriteLine(player1.getName() + " draw last card is " + tempc1[i - 1].nameRank() + tempc1[i - 1].nameSuit()); Console.WriteLine(player2.getName() + " draw last card is " + tempc2[i - 1].nameRank() + tempc2[i - 1].nameSuit()); if (tempc1[i - 1].getRank() < tempc2[i - 1].getRank()) { Console.WriteLine(player1.getName() + " Win! and get " + Convert.ToString(round*2) + "+2 Cards"); for (i = 0; i < round + 1; i++) { player1.addPile(tempc1[i]); player1.addPile(tempc2[i]); } } else if (tempc1[i - 1].getRank() > tempc2[i - 1].getRank()) { Console.WriteLine(player2.getName() + " Win! and get " + Convert.ToString(round*2) + "+2 Cards"); for (i = 0; i < round + 1; i++) { player2.addPile(tempc1[i]); player2.addPile(tempc2[i]); } } else { Console.WriteLine("Equal again! Return all cards to your deck, then shuffle it."); for(i=0;i<round+1;i++) { player1.addCard(tempc1[i]); player2.addCard(tempc2[i]); } player1.deckShuff(); player2.deckShuff(); } } Console.WriteLine(player1.getName() + " has " + player1.getNumPile() + " Cards in Pile"); Console.WriteLine(player2.getName() + " has " + player2.getNumPile() + " Cards in Pile"); Console.ReadKey(); } while (player1.getNumdeck() > 0); if(player1.getNumPile() > player2.getNumPile()) { Console.WriteLine("\nThe Winner is " +player1.getName()); } else if (player1.getNumPile() < player2.getNumPile()) { Console.WriteLine("\nThe Winner is " + player2.getName()); } else { Console.WriteLine("\nPlease New Game Again."); } Console.ReadKey(); }
public void play() { CardDeck cd = new CardDeck(); string n1, n2; Console.Write("What's player1 name ? : "); n1 = Console.ReadLine(); Console.Write("What's player2 name ? : "); n2 = Console.ReadLine(); cd.shuffle(); p1 = new Player(n1); p2 = new Player(n2); while (cd.getSize() >= 2) { p1.collectCard(cd.deal()); p2.collectCard(cd.deal()); } p1.useWonPile(); p2.useWonPile(); Pile down = new Pile(); int t = 0; while (p1.numCards()>0) { if (!enoughCards(1)) break; Card c1 = p1.playCard(); Card c2 = p2.playCard(); Console.WriteLine("\nTurn " + t + ": "); t++; Console.Write(p1.getName() + ": " + c1 + " "); Console.Write(p2.getName() + ": " + c2 + " "); if (c1.compareTo(c2) > 0) { p1.KeepCard(); } else if (c1.compareTo(c2) < 0) { p2.KeepCard(); } else { temp1 = new Card[14]; temp2 = new Card[14]; temp1[0] = c1; temp2[0] = c2; down.clear(); down.addCard(c1); down.addCard(c2); bool done = false; do { int num = c1.getRank(); if (!enoughCards(num)) break; Console.Write("\nWar! Players put down "); Console.WriteLine(num + " card(s)."); for (int m = 1; m <= num; m++) { c1 = p1.playCard(); c2 = p2.playCard(); temp1[m] = c1; temp2[m] = c2; down.addCard(c1); down.addCard(c2); } Console.Write(p1.getName() + ": " + c1 + " "); Console.Write(p2.getName() + ": " + c2 + " "); if (c1.compareTo(c2) == 0) { for (int m = num; m >= 0 ; m--) { p1.collectCard(temp1[m]); p2.collectCard(temp2[m]); } done = true; } else if (c1.compareTo(c2) > 0) { for (int m = 1; m <= num+1; m++) { p1.KeepCard(); } done = true; } else if (c1.compareTo(c2) < 0) { for (int m = 1; m <= num+1; m++) { p2.KeepCard(); } done = true; } } while (!done); } Console.WriteLine("Card "+ p1.getName()+ " : "+p1.numCards() + " And Card " + p2.getName() + " : " + p2.numCards()); Console.WriteLine(p1.getName()+" Score : "+p1.getscore() + " And "+p2.getName() + " Score : "+ p2.getscore()); } }
static void Main(string[] args) { List<IAttack> fighters = new List<IAttack>(); List<Stats> info = new List<Stats>(); for (int i = 0; i < 2; i++) { Player player = new Player(); Enemy enemy = new Enemy(); fighters.Add(player); fighters.Add(enemy); } for (int i = 0; i < 2; i++) { Player player = new Player(); Enemy enemy = new Enemy(); } for (int a = 0; a < 1; a++) foreach (IAttack i in fighters) { i.attack(); } foreach (Stats a in fighters) { a.stats(); } Console.ReadLine(); }